//
//  MBProgressHUD+KSDHelp.m
//  specialksudi
//
//  Created by 庄彪 on 16/4/19.
//  Copyright © 2016年 ksudi. All rights reserved.
//

#import "MBProgressHUD+KSDHelp.h"

static NSTimeInterval const kDefaultHUDShowTimeInterval = 2.f;
#define kDefaultDetailTextFont [UIFont systemFontOfSize:15]
#define kDefaultContentBackgroundColor [UIColor blackColor];
#define kDefaultContentFontColor [UIColor whiteColor]

@implementation MBProgressHUD (KSDHelp)

#pragma mark Private Methods

+ (MBProgressHUD *)KSD_customProgressHUDAddedTo:(UIView *)view {
    if (view == nil) view = [UIApplication sharedApplication].keyWindow;
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.label.textColor = kDefaultContentFontColor;
    hud.detailsLabel.font = kDefaultDetailTextFont;
    hud.contentColor = kDefaultContentFontColor;
    hud.bezelView.color = kDefaultContentBackgroundColor;
    hud.removeFromSuperViewOnHide = YES;
    return hud;
}

+ (void)KSD_show:(NSString *)text icon:(NSString *)icon view:(UIView *)view {
    MBProgressHUD *hud = [self KSD_customProgressHUDAddedTo:view];
    hud.mode = MBProgressHUDModeCustomView;
    hud.label.text = text;
    hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", icon]]];
    [hud hideAnimated:YES afterDelay:kDefaultHUDShowTimeInterval];
}

#pragma mark Public Methods

+ (void)KSD_showSuccess:(NSString *)success {
    [self KSD_showSuccess:success toView:nil];
}

+ (void)KSD_showSuccess:(NSString *)success toView:(UIView *)view {
    [self KSD_show:success icon:@"" view:view];
}

+ (void)KSD_showError:(NSString *)error {
    [self KSD_showError:error toView:nil];
}

+ (void)KSD_showError:(NSString *)error toView:(UIView *)view{
    [self KSD_show:error icon:@"" view:view];
}

+ (MBProgressHUD *)KSD_showMessage:(NSString *)message {
    return [self KSD_showMessage:message toView:nil];
}

+ (MBProgressHUD *)KSD_showMessage:(NSString *)message toView:(UIView *)view {
    MBProgressHUD *hud = [self KSD_customProgressHUDAddedTo:view];
    hud.mode = MBProgressHUDModeText;
    hud.label.text = message;
    [hud hideAnimated:YES afterDelay:kDefaultHUDShowTimeInterval];
    return hud;
}

+ (MBProgressHUD *)KSD_showDetailMessage:(NSString *)message {
    return [MBProgressHUD KSD_showDetailMessage:message toView:nil];
}

+ (MBProgressHUD *)KSD_showDetailMessage:(NSString *)message toView:(UIView *)view {
    MBProgressHUD *hud = [self KSD_customProgressHUDAddedTo:view];
    hud.mode = MBProgressHUDModeText;
    hud.detailsLabel.text = message;
    [hud hideAnimated:YES afterDelay:kDefaultHUDShowTimeInterval];
    return hud;
}

+ (MBProgressHUD *)KSD_showMessage:(NSString *)message afterDelay:(NSTimeInterval)afterDelay {
    return [self KSD_showMessage:message toView:nil afterDelay:afterDelay];
}

+ (MBProgressHUD *)KSD_showMessage:(NSString *)message toView:(UIView *)view afterDelay:(NSTimeInterval)afterDelay {
    MBProgressHUD *hud = [self KSD_customProgressHUDAddedTo:view];
    hud.mode = MBProgressHUDModeText;
    hud.label.text = message;
    [hud hideAnimated:YES afterDelay:afterDelay];
    return hud;
}

+ (MBProgressHUD *)KSD_showLoading:(NSString *)message {
    return [self KSD_showLoading:message toView:nil];
}

+ (MBProgressHUD *)KSD_showLoading:(NSString *)message toView:(UIView *)view {
    MBProgressHUD *hud = [self KSD_customProgressHUDAddedTo:view];
    hud.label.text = message;
    return hud;
}

+ (void)KSD_hideHUD {
    [self KSD_hideHUDForView:nil];
}

+ (void)KSD_hideHUDForView:(UIView *)view {
    if (view == nil) view = [UIApplication sharedApplication].keyWindow;
    [self hideHUDForView:view animated:YES];
}


@end
